Printing on the IIgs under GS/OS
By Richard Bennett
Copyright (c) 1992 Apple Users' Group, Sydney
Republished from Applecations, a publication of the Apple Users' Group, Sydney, Australia.
Because of the way the system software was designed, printing is usually a trouble free process on the IIgs. The applications all talk to a standard interface, the Print Manager, and it in turn managers your printer. In this way, it is the system software that needs to know about the printer, and not the application.
To connect a printer to your IIgs, you simply plug it in, use the System Disk Installer to install the driver, and then select it from the Direct Connect Printer CDEV in the Control Panel. All of your applications will now be able to use your printer correctly, because they only talk to the standard interface, the Print Manager.
Now this is great for the developers of applications, such as AppleWorks GS, because upgrades to the system software usually include support for more printers, which is similar to getting a free upgrade to the application! An example of this is the new StyleWriter driver that comes with System 6.0. But how about support for printers which Apple has yet to provide a driver for? We know it's possible, because both Seven Hills and Vitesse have released printer drivers which are not included with the IIgs system software. For this, Apple have once again provided a standard documented interface, which allows anyone who wants to write a printer driver to do so.
So how does printing on the IIgs work?
To keep the system as open as possible, there are two different drivers which are required before you can print anything. The first is called the printer driver, and it receives commands from the Print manager to print sections of a graphic image. It is the printer driver's job to take the graphic image and convert it into a stream of control characters which the printer will understand. As an example, the following uses an ImageWriter command to print a row of eight dots in the middle of the current print line:
1B 47 20 20 20 38 10 10 10 10 10 10 10 10
The above line, in hex, tells the printer to print the eight (20 20 20 38) characters 10 10 10 10 10 10 10 10, as graphics (1B 47). The bit pattern of 10 is a dot in the middle of the print line.
Once the printer driver has converted the graphics into the printer control characters, it sends them on to the port driver, via the Print Manager. It is the port driver's job to take the characters it is given, and send them to the port or slot to which the printer is connected.
So by "mixing and matching" printer and port drivers, you should be able to reach a combination that matches your hardware. The most common would be an ImageWriter II connected to the IIgs printer port, so the printer driver would be "ImageWriter", and the port driver would be "Printer". The operating mode of the port/slot can be chosen with the CDEV provided for the port/slot. In the case above, there is a Printer CDEV which selects how the port will operate.
The loading of these drivers into memory is controlled by the Print Manager, and although they are called "drivers", they are not actually loaded in with all your other drivers (eg. AppleDisk.3.5, SCSI.HD).
When the Print Manager decides that it is time to print, it loads the printer and port drivers into memory and starts them up. When it is finished with them, they're shut down, and marked as purgable to free up the memory if needed. But how does it know which drivers to use?
When you close the Direct Connect Printer CDEV in the Control Panel, it writes your selection out to the file *:System:Drivers:Printer.Setup, and then unloads the current drivers from memory. When the Print Manager starts, it loads the file into memory and works out which drivers it must load. If the Print Manager is already started, the CDev would have unloaded the drivers from memory, and the Print Manager simply loads the new ones in according to the entries in the setup file.
So we now know how the drivers interact with the Print Manager, but how does an application actually print something?
To print a document, the application simply sends the graphical image of the document to the Print Manager. It first tells the Print Manager to start a new document, then it tells it to start a new page, and starts drawing the document into memory. But first a little Toolbox theory.
Applications always draw their documents into memory. Sounds simple enough. When the user wants to see the document (such as a word processor document in AppleWorks GS), the application still draws it into memory, however in this special case, the memory just happens to be the memory belonging to the screen. The application doesn't care, as it still draws the document the same way. When a document is saved to disk as a graphic image, it is simply drawn into memory which is not part of the screen, and then that memory is saved to disk.
So when the application tells the Print Manager to start a new document, the Print Manager tells it to draw the first page into memory, but not part of the screen memory. When finished, the application tells the Print Manager that the page is complete, and the Print Manager then passes the graphic image to the printer driver. This process continues for each page until the application tells the Print Manager that the document is complete. So as we can see, the Print Manager doesn't really do any of the hard work, and mostly acts as a mediator between the application and the various drivers.
The imaging performed by the printer driver, is always graphical. In the case of text in a word processing document, the text is drawn into memory as a graphical image, and sent to the printer as such. Only in the ImageWriter "Text Only" mode, is actual text sent to the printer.
Ok, so all this is pretty straight forward, but there are a number of things that happen in the print process that are not so obvious. One of those is called "option sensing".
Most applications which allow printing also offer a Page Setup option from the file menu. This option seems to be specific for the printer selected in the CDEV, however the applications aren't meant to be specific about each printer, so how come? There is a Print Manager tool call, not surprisingly called _PageSetUp, which tells the printer driver to present the dialog. This way all the application has to do is issue the tool call, and the currently selected printer driver does the rest.
With the ImageWriter II, there are two pop-up menus at the bottom of this dialog, which allow you to choose which type of ribbon you are
using (colour or black), and if you have a sheet feeder installed. However, if you only have a black ribbon in the ImageWriter, then only that menu option will be allowed to be chosen (the word "colour" will be dimmed). So again, how come?
The ImageWriter II is capable of not only receiving characters from the Apple II, but also sending characters back again. When the ImageWriter II receives the two characters "ESC" and "?", it sends back a string indicating which options it has installed. The string always starts with "IW", and is followed by two characters indicating the platen width, commonly "10". Next comes a "C" if there is a colour ribbon, and then an "F" if there is a sheet feeder. So for a 10" ImageWriter II with a black ribbon and a sheet feeder, the ImageWriter II would send back the characters "IW10F".
So all the printer driver does is send "ESC" and "?", and the printer responds by telling it what is installed as an option. It then modifies the _PageSetUp dialog accordingly. If you have a colour ribbon, you will be allowed to choose either "colour" or "black", but if you only have black, then you will only be allowed to choose "black".
The ImageWriter LQ also responds to the "ESC" "?" command, and returns information on the various sheet feeders it has available, which feed mode is currently activated, and if it has an envelope feeder.
Other third party printers may also respond to special query commands if they have appropriate GS/OS drivers.
The port drivers on the other hand, are required to be printer independent. The requirement for a port driver is to simply take input data, and get it safely out of the IIgs. Whether it then goes to an ImageWriter, LaserWriter or even an ASCII terminal, is completely up to the user.
The "Printer" port driver under GS/OS uses the Text Tools to re-direct screen output to the device in slot 1. It first checks to see if the "Printer Port" has been selected for slot 1 in the Control Panel, and then issues various initialisation commands to the firmware, in much the same way as a BASIC program would issue a PR#1 and send it appropriate control-I firmware commands. Once the print has finished, the port driver then re-initialises the port, again by using control-I commands, and re-directs output back to the screen. If you think this stinks of Apple hypocrisy, you're right, as Apple recommends that developers NOT use the Text Tools!
For printers that accept data at higher speeds than the ImageWriter's 9600 bits per second, this method of using the Text Tools can also marginally slow down the print process, due to Tool Locator overheads, and the generic nature of the Text Tools. I know high speed drivers are available from Seven Hills, however these obviously would not work with the ImageWriter.
Port drivers for third party printer cards may also use the inbuilt firmware of the card instead of going directly to the hardware, however, these wouldn't have the same processing overheads as that of the Text Tools.
And that, simply, is the Print Manager. A control point between various programs inside the IIgs, that all come together to enable the user to print documents. A radical improvement on the way the Apple //e handled printers.
With the Apple drivers such as ImageWriter I, ImageWriter II, ImageWriter LQ, LaserWriter and with System 6.0 a StyleWriter driver, there is a wide choice of printers you can buy. And with the drivers from Seven Hills and Vitesse, which include many different brands of laser and inkjet drivers, you can now choose from a whole range of Macintosh and IBM printers.
So once again, why would you want anything other than an Apple IIgs?!

THIS CONTENT COPYRIGHT © 2007, APPLE MACINTOSH USERS' GROUP, SYDNEY
Permission has been obtained to make this material available on the Internet.

Permission is hereby granted for non-profit user groups to republish this content.
PLEASE CREDIT THE AUTHOR AND THE SOURCE: Applecations, publication of the Apple Users' Group, Sydney, Australia

THIS PAGE COPYRIGHT © 2007, ANDREW ROUGHAN